<?php

namespace App\Http\Criteria;

use App\Repository\Criteria;
use App\Repository\Constracts\RepositoryInterface as Repository;

class PaginateCriteria extends Criteria
{
    private $pageSize;
    private $pageNumber;

    public function __construct($pageNumber, $pageSize = 5)
    {
        $this->pageNumber = --$pageNumber;
        $this->pageSize = $pageSize;
    }

    public function apply($model, Repository $repository)
    {
        return $model->skip($this->pageSize * $this->pageNumber)->take($this->pageSize);
    }

}
